package com.cdm.beans.cdm;

import net.sf.frails.JSFHelper;
import net.sf.frails.actions.BaseAction;
import net.sf.frails.bean.annotations.DefMbean;
import net.sf.frails.bean.annotations.PreRender;
import net.sf.frails.bean.annotations.PreRestoreView;
import net.sf.frails.bean.annotations.Prop;
import net.sf.frails.utils.WebResourceUtils;

import org.apache.myfaces.custom.fileupload.UploadedFile;

import com.cdm.domain.dao.ContentDAO;
import com.cdm.persistence.Content;
import com.cdm.persistence.User;
import com.cdm.util.Constants;
import com.vivo.util.DTool;

@DefMbean
public class ContentDecryptBean extends BaseAction {
	@Prop
	UploadedFile uploadedFile;

	@Prop
	String name;

	@Prop
	User loginUser;

	@Prop
	String id = "Cain";

	@Prop
	Content content;

	@PreRender(failOutcome = "")
	public boolean init() {
		Object object = JSFHelper.getFromApplication(Constants.LOGIN_USER_KEY);
		if (object instanceof User && object != null) {
			loginUser = (User) object;
		}
		if (this.content == null) {
			JSFHelper.addMessage("错误:没有找到节目信息");
		}
		DTool.d.debug("Enter CDM Home Page");
		return true;
	}

	@PreRestoreView
	public void listen() {
		System.out.println("\nlistening restore view " + getClass() + "\n");
	}

	public void upload() {
		name = WebResourceUtils.parseUploadedFilename(uploadedFile.getName());
		WebResourceUtils.upload(uploadedFile, name);
	}
}
